1   /*
2    * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   */
23  
24  /* @test
25   * @summary unit tests for java.lang.invoke.MethodType
26   * @compile MethodTypeTest.java
27   * @run junit/othervm test.java.lang.invoke.MethodTypeTest
28   */
29  
30  package test.java.lang.invoke;
31  
32  import java.lang.invoke.MethodType;
33  import java.lang.reflect.Method;
34  
35  import java.util.*;
36  import org.junit.*;
37  import static org.junit.Assert.*;
38  
39  /**
40   *
41   * @author jrose
42   */
43  public class MethodTypeTest {
44  
45      private Class<?> rtype;
46      private Class<?>[] ptypes;
47      private MethodType mt_viS, mt_OO, mt_OO2, mt_vv, mt_Vv, mt_Ov;
48      private MethodType mt_iSI, mt_ISi, mt_ISI, mt_iSi;
49      private MethodType mt_viO, mt_iO2, mt_OOi, mt_iOi;
50      private MethodType mt_VIO, mt_IO2, mt_OOI, mt_IOI, mt_VIS;
51      private MethodType mt_vOiSzA, mt_OO99;
52      private MethodType[] GALLERY;
53      private Method compareTo;
54  
55      @Before
56      public void setUp() throws Exception {
57          rtype = void.class;
58          ptypes = new Class<?>[] { int.class, String.class };
59  
60          mt_viS = MethodType.methodType(void.class, int.class, String.class);
61          mt_OO = MethodType.methodType(Object.class, Object.class);
62          mt_OO2 = MethodType.methodType(Object.class, Object.class, Object.class);
63          mt_vv = MethodType.methodType(void.class);
64          mt_Vv = MethodType.methodType(Void.class);
65          mt_Ov = MethodType.methodType(Object.class);
66          mt_iSI = MethodType.methodType(int.class, String.class, Integer.class);
67          mt_ISi = MethodType.methodType(Integer.class, String.class, int.class);
68          mt_ISI = MethodType.methodType(Integer.class, String.class, Integer.class);
69          mt_iSi = MethodType.methodType(int.class, String.class, int.class);
70  
71          compareTo = String.class.getDeclaredMethod("compareTo", String.class);
72  
73          mt_viO = MethodType.methodType(void.class, int.class, Object.class);
74          mt_iO2 = MethodType.methodType(int.class, Object.class, Object.class);
75          mt_OOi = MethodType.methodType(Object.class, Object.class, int.class);
76          mt_iOi = MethodType.methodType(int.class, Object.class, int.class);
77  
78          mt_VIO = MethodType.methodType(Void.class, Integer.class, Object.class);
79          mt_IO2 = MethodType.methodType(Integer.class, Object.class, Object.class);
80          mt_OOI = MethodType.methodType(Object.class, Object.class, Integer.class);
81          mt_IOI = MethodType.methodType(Integer.class, Object.class, Integer.class);
82          mt_VIS = MethodType.methodType(Void.class, Integer.class, String.class);
83  
84          mt_vOiSzA = MethodType.methodType(void.class, Object.class, int.class, String.class, boolean.class, Object[].class);
85          mt_OO99 = MethodType.genericMethodType(99);
86  
87          GALLERY = new MethodType[] {
88              mt_viS, mt_OO, mt_OO2, mt_vv, mt_Vv, mt_Ov,
89              mt_iSI, mt_ISi, mt_ISI, mt_iSi,
90              mt_viO, mt_iO2, mt_OOi, mt_iOi,
91              mt_VIO, mt_IO2, mt_OOI, mt_IOI,
92              mt_VIS, mt_vOiSzA, mt_OO99
93          };
94      }
95  
96      @After
97      public void tearDown() throws Exception {
98      }
99  
100     /** Make sure the method types are all distinct. */
101     @Test
102     public void testDistinct() {
103         List<MethodType> gallery2 = new ArrayList<>();
104         for (MethodType mt : GALLERY) {
105             assertFalse(mt.toString(), gallery2.contains(mt));
106             gallery2.add(mt);
107         }
108         // check self-equality also:
109         assertEquals(Arrays.asList(GALLERY), gallery2);
110     }
111 
112     /**
113      * Test of make method, of class MethodType.
114      */
115     @Test
116     public void testMake_Class_ClassArr() {
117         System.out.println("make (from type array)");
118         MethodType result = MethodType.methodType(rtype, ptypes);
119         assertSame(mt_viS, result);
120     }
121 
122     /**
123      * Test of make method, of class MethodType.
124      */
125     @Test
126     public void testMake_Class_List() {
127         System.out.println("make (from type list)");
128         MethodType result = MethodType.methodType(rtype, Arrays.asList(ptypes));
129         assertSame(mt_viS, result);
130     }
131 
132     /**
133      * Test of make method, of class MethodType.
134      */
135     @Test
136     public void testMake_3args() {
137         System.out.println("make (from type with varargs)");
138         MethodType result = MethodType.methodType(rtype, ptypes[0], ptypes[1]);
139         assertSame(mt_viS, result);
140     }
141 
142     /**
143      * Test of make method, of class MethodType.
144      */
145     @Test
146     public void testMake_Class() {
147         System.out.println("make (from single type)");
148         Class<?> rt = Integer.class;
149         MethodType expResult = MethodType.methodType(rt, new Class<?>[0]);
150         MethodType result = MethodType.methodType(rt);
151         assertSame(expResult, result);
152     }
153 
154     @Test
155     public void testMakeGeneric() {
156         System.out.println("makeGeneric");
157         int objectArgCount = 2;
158         MethodType expResult = mt_OO2;
159         MethodType result = MethodType.genericMethodType(objectArgCount);
160         assertSame(expResult, result);
161     }
162 
163     /**
164      * Test of make method, of class MethodType.
165      */
166     @Test
167     public void testMake_MethodType() {
168         System.out.println("make (from rtype, MethodType)");
169         MethodType expResult = mt_iO2;
170         MethodType result = MethodType.methodType(int.class, mt_IO2);
171         assertSame(expResult, result);
172     }
173 
174     /**
175      * Test of make method, of class MethodType.
176      */
177     @Test
178     public void testMake_String_ClassLoader() {
179         System.out.println("make (from bytecode signature)");
180         ClassLoader loader = null;
181         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
182         String obj = "Ljava/lang/Object;";
183         assertEquals(obj, concat(Object.class));
184         String[] expResults = {
185             "(ILjava/lang/String;)V",
186             concat("(", obj, 2, ")", Object.class),
187             "()V", "()"+obj,
188             concat("(", String.class, Integer.class, ")I"),
189             concat("(", String.class, "I)", Integer.class),
190             concat("(", String.class, Integer.class, ")", Integer.class),
191             concat("(", String.class, "I)I")
192         };
193         for (int i = 0; i < instances.length; i++) {
194             MethodType instance = instances[i];
195             String result = instance.toMethodDescriptorString();
196             assertEquals("#"+i, expResults[i], result);
197             MethodType parsed = MethodType.fromMethodDescriptorString(result, loader);
198             assertSame("--#"+i, instance, parsed);
199         }
200     }
201     private static String concat(Object... parts) {
202         StringBuilder sb = new StringBuilder();
203         Object prevPart = "";
204         for (Object part : parts) {
205             if (part instanceof Class) {
206                 part = "L"+((Class)part).getName()+";";
207             }
208             if (part instanceof Integer) {
209                 for (int n = (Integer) part; n > 1; n--)
210                     sb.append(prevPart);
211                 part = "";
212             }
213             sb.append(part);
214             prevPart = part;
215         }
216         return sb.toString().replace('.', '/');
217     }
218 
219     @Test
220     public void testHasPrimitives() {
221         System.out.println("hasPrimitives");
222         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
223         boolean[] expResults =   {true,   false,  true,  false, true,   true,   false,  true};
224         for (int i = 0; i < instances.length; i++) {
225             boolean result = instances[i].hasPrimitives();
226             assertEquals("#"+i, expResults[i], result);
227         }
228     }
229 
230     @Test
231     public void testHasWrappers() {
232         System.out.println("hasWrappers");
233         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
234         boolean[] expResults =   {false,  false,  false, false, true,   true,   true,   false};
235         for (int i = 0; i < instances.length; i++) {
236             System.out.println("  hasWrappers "+instances[i]);
237             boolean result = instances[i].hasWrappers();
238             assertEquals("#"+i, expResults[i], result);
239         }
240     }
241 
242     @Test
243     public void testErase() {
244         System.out.println("erase");
245         MethodType[] instances  = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
246         MethodType[] expResults = {mt_viO, mt_OO2, mt_vv, mt_Ov, mt_iO2, mt_OOi, mt_OO2, mt_iOi};
247         for (int i = 0; i < instances.length; i++) {
248             MethodType result = instances[i].erase();
249             assertSame("#"+i, expResults[i], result);
250         }
251     }
252 
253     @Test
254     public void testGeneric() {
255         System.out.println("generic");
256         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
257         MethodType[] expResults = {mt_OO2, mt_OO2, mt_Ov, mt_Ov, mt_OO2, mt_OO2, mt_OO2, mt_OO2};
258         for (int i = 0; i < instances.length; i++) {
259             MethodType result = instances[i].generic();
260             assertSame("#"+i, expResults[i], result);
261         }
262     }
263 
264     @Test
265     public void testWrap() {
266         System.out.println("wrap");
267         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
268         MethodType[] expResults = {mt_VIS, mt_OO2, mt_Vv, mt_Ov, mt_ISI, mt_ISI, mt_ISI, mt_ISI};
269         for (int i = 0; i < instances.length; i++) {
270             MethodType result = instances[i].wrap();
271             assertSame("#"+i, expResults[i], result);
272         }
273     }
274 
275     @Test
276     public void testUnwrap() {
277         System.out.println("unwrap");
278         MethodType[] instances =  {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
279         MethodType[] expResults = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSi, mt_iSi, mt_iSi, mt_iSi};
280         for (int i = 0; i < instances.length; i++) {
281             MethodType result = instances[i].unwrap();
282             assertSame("#"+i, expResults[i], result);
283         }
284     }
285 
286     /**
287      * Test of parameterType method, of class MethodType.
288      */
289     @Test
290     public void testParameterType() {
291         System.out.println("parameterType");
292         for (int num = 0; num < ptypes.length; num++) {
293             MethodType instance = mt_viS;
294             Class<?> expResult = ptypes[num];
295             Class<?> result = instance.parameterType(num);
296             assertSame(expResult, result);
297         }
298     }
299 
300     /**
301      * Test of parameterCount method, of class MethodType.
302      */
303     @Test
304     public void testParameterCount() {
305         System.out.println("parameterCount");
306         MethodType instance = mt_viS;
307         int expResult = 2;
308         int result = instance.parameterCount();
309         assertEquals(expResult, result);
310     }
311 
312     /**
313      * Test of returnType method, of class MethodType.
314      */
315     @Test
316     public void testReturnType() {
317         System.out.println("returnType");
318         MethodType instance = mt_viS;
319         Class<?> expResult = void.class;
320         Class<?> result = instance.returnType();
321         assertSame(expResult, result);
322     }
323 
324     /**
325      * Test of parameterList method, of class MethodType.
326      */
327     @Test
328     public void testParameterList() {
329         System.out.println("parameterList");
330         MethodType instance = mt_viS;
331         List<Class<?>> expResult = Arrays.asList(ptypes);
332         List<Class<?>> result = instance.parameterList();
333         assertEquals(expResult, result);
334     }
335 
336     /**
337      * Test of parameterArray method, of class MethodType.
338      */
339     @Test
340     public void testParameterArray() {
341         System.out.println("parameterArray");
342         MethodType instance = mt_viS;
343         Class<?>[] expResult = ptypes;
344         Class<?>[] result = instance.parameterArray();
345         assertEquals(Arrays.asList(expResult), Arrays.asList(result));
346     }
347 
348     /**
349      * Test of equals method, of class MethodType.
350      */
351     @Test
352     public void testEquals_Object() {
353         System.out.println("equals");
354         Object x = null;
355         MethodType instance = mt_viS;
356         boolean expResult = false;
357         boolean result = instance.equals(x);
358         assertEquals(expResult, result);
359     }
360 
361     /**
362      * Test of equals method, of class MethodType.
363      */
364     @Test
365     public void testEquals_MethodType() {
366         System.out.println("equals");
367         MethodType that = mt_viS;
368         MethodType instance = mt_viS;
369         boolean expResult = true;
370         boolean result = instance.equals(that);
371         assertEquals(expResult, result);
372     }
373 
374     /**
375      * Test of hashCode method, of class MethodType.
376      */
377     @Test
378     public void testHashCode() {
379         System.out.println("hashCode");
380         MethodType instance = mt_viS;
381         ArrayList<Class<?>> types = new ArrayList<Class<?>>();
382         types.add(instance.returnType());
383         types.addAll(instance.parameterList());
384         int expResult = types.hashCode();
385         int result = instance.hashCode();
386         assertEquals(expResult, result);
387     }
388 
389     /**
390      * Test of toString method, of class MethodType.
391      */
392     @Test
393     public void testToString() {
394         System.out.println("toString");
395         MethodType[] instances = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSI, mt_ISi, mt_ISI, mt_iSi};
396         //String expResult = "void[int, class java.lang.String]";
397         String[] expResults = {
398             "(int,String)void",
399             "(Object,Object)Object",
400             "()void",
401             "()Object",
402             "(String,Integer)int",
403             "(String,int)Integer",
404             "(String,Integer)Integer",
405             "(String,int)int"
406         };
407         for (int i = 0; i < instances.length; i++) {
408             MethodType instance = instances[i];
409             String result = instance.toString();
410             System.out.println("#"+i+":"+result);
411             assertEquals("#"+i, expResults[i], result);
412         }
413     }
414 
415     private static byte[] writeSerial(Object x) throws java.io.IOException {
416         try (java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
417              java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(bout)
418              ) {
419             out.writeObject(x);
420             out.flush();
421             return bout.toByteArray();
422         }
423     }
424     private static Object readSerial(byte[] wire) throws java.io.IOException, ClassNotFoundException {
425         try (java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(wire);
426              java.io.ObjectInputStream in = new java.io.ObjectInputStream(bin)) {
427             return in.readObject();
428         }
429     }
430     private static void testSerializedEquality(Object x) throws java.io.IOException, ClassNotFoundException {
431         if (x instanceof Object[])
432             x = Arrays.asList((Object[]) x);  // has proper equals method
433         byte[] wire = writeSerial(x);
434         Object y = readSerial(wire);
435         assertEquals(x, y);
436     }
437 
438     /** Test (de-)serialization. */
439     @Test
440     public void testSerialization() throws Throwable {
441         System.out.println("serialization");
442         for (MethodType mt : GALLERY) {
443             testSerializedEquality(mt);
444         }
445         testSerializedEquality(GALLERY);
446 
447         // Make a list of mixed objects:
448         List<Object> stuff = new ArrayList<>();
449         Collections.addAll(stuff, GALLERY);  // copy #1
450         Object[] triples = Arrays.copyOfRange(GALLERY, 0, GALLERY.length/2);
451         Collections.addAll(stuff, triples);  // copy #3 (partial)
452         for (MethodType mt : GALLERY) {
453             Collections.addAll(stuff, mt.parameterArray());
454         }
455         Collections.shuffle(stuff, new Random(292));
456         Collections.addAll(stuff, GALLERY);  // copy #2
457         testSerializedEquality(stuff);
458     }
459 
460     /** Test serialization formats. */
461     @Test
462     public void testPortableSerialFormat() throws Throwable {
463         System.out.println("portable serial format");
464         boolean generateData = false;
465         //generateData = true;  // set this true to generate the following input data:
466         Object[][] cases = {
467             { mt_vv, new byte[] {  // ()void
468                     (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x1b,
469                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
470                     (byte)0x67, (byte)0x2e, (byte)0x69, (byte)0x6e, (byte)0x76, (byte)0x6f, (byte)0x6b, (byte)0x65,
471                     (byte)0x2e, (byte)0x4d, (byte)0x65, (byte)0x74, (byte)0x68, (byte)0x6f, (byte)0x64, (byte)0x54,
472                     (byte)0x79, (byte)0x70, (byte)0x65, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
473                     (byte)0x00, (byte)0x01, (byte)0x24, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
474                     (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x04, (byte)0x76, (byte)0x6f, (byte)0x69, (byte)0x64,
475                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
476                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00,
477                     (byte)0x12, (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e,
478                     (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x43, (byte)0x6c, (byte)0x61,
479                     (byte)0x73, (byte)0x73, (byte)0x3b, (byte)0xab, (byte)0x16, (byte)0xd7, (byte)0xae, (byte)0xcb,
480                     (byte)0xcd, (byte)0x5a, (byte)0x99, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
481                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78,
482                 } },
483             { mt_OO, new byte[] {  // (Object)Object
484                     (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x1b,
485                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
486                     (byte)0x67, (byte)0x2e, (byte)0x69, (byte)0x6e, (byte)0x76, (byte)0x6f, (byte)0x6b, (byte)0x65,
487                     (byte)0x2e, (byte)0x4d, (byte)0x65, (byte)0x74, (byte)0x68, (byte)0x6f, (byte)0x64, (byte)0x54,
488                     (byte)0x79, (byte)0x70, (byte)0x65, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
489                     (byte)0x00, (byte)0x01, (byte)0x24, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
490                     (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x10, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61,
491                     (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x4f, (byte)0x62,
492                     (byte)0x6a, (byte)0x65, (byte)0x63, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
493                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78,
494                     (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00, (byte)0x12, (byte)0x5b, (byte)0x4c, (byte)0x6a,
495                     (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67,
496                     (byte)0x2e, (byte)0x43, (byte)0x6c, (byte)0x61, (byte)0x73, (byte)0x73, (byte)0x3b, (byte)0xab,
497                     (byte)0x16, (byte)0xd7, (byte)0xae, (byte)0xcb, (byte)0xcd, (byte)0x5a, (byte)0x99, (byte)0x02,
498                     (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
499                     (byte)0x71, (byte)0x00, (byte)0x7e, (byte)0x00, (byte)0x03, (byte)0x78,
500                 } },
501             { mt_vOiSzA, new byte[] {  // (Object,int,String,boolean,Object[])void
502                     (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05, (byte)0x73, (byte)0x72, (byte)0x00, (byte)0x1b,
503                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
504                     (byte)0x67, (byte)0x2e, (byte)0x69, (byte)0x6e, (byte)0x76, (byte)0x6f, (byte)0x6b, (byte)0x65,
505                     (byte)0x2e, (byte)0x4d, (byte)0x65, (byte)0x74, (byte)0x68, (byte)0x6f, (byte)0x64, (byte)0x54,
506                     (byte)0x79, (byte)0x70, (byte)0x65, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
507                     (byte)0x00, (byte)0x01, (byte)0x24, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
508                     (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x04, (byte)0x76, (byte)0x6f, (byte)0x69, (byte)0x64,
509                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
510                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x75, (byte)0x72, (byte)0x00,
511                     (byte)0x12, (byte)0x5b, (byte)0x4c, (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e,
512                     (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x43, (byte)0x6c, (byte)0x61,
513                     (byte)0x73, (byte)0x73, (byte)0x3b, (byte)0xab, (byte)0x16, (byte)0xd7, (byte)0xae, (byte)0xcb,
514                     (byte)0xcd, (byte)0x5a, (byte)0x99, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70,
515                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x10,
516                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
517                     (byte)0x67, (byte)0x2e, (byte)0x4f, (byte)0x62, (byte)0x6a, (byte)0x65, (byte)0x63, (byte)0x74,
518                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
519                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x76, (byte)0x72, (byte)0x00,
520                     (byte)0x03, (byte)0x69, (byte)0x6e, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
521                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x78,
522                     (byte)0x70, (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x10, (byte)0x6a, (byte)0x61, (byte)0x76,
523                     (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e, (byte)0x67, (byte)0x2e, (byte)0x53,
524                     (byte)0x74, (byte)0x72, (byte)0x69, (byte)0x6e, (byte)0x67, (byte)0xa0, (byte)0xf0, (byte)0xa4,
525                     (byte)0x38, (byte)0x7a, (byte)0x3b, (byte)0xb3, (byte)0x42, (byte)0x02, (byte)0x00, (byte)0x00,
526                     (byte)0x78, (byte)0x70, (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x07, (byte)0x62, (byte)0x6f,
527                     (byte)0x6f, (byte)0x6c, (byte)0x65, (byte)0x61, (byte)0x6e, (byte)0x00, (byte)0x00, (byte)0x00,
528                     (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
529                     (byte)0x78, (byte)0x70, (byte)0x76, (byte)0x72, (byte)0x00, (byte)0x13, (byte)0x5b, (byte)0x4c,
530                     (byte)0x6a, (byte)0x61, (byte)0x76, (byte)0x61, (byte)0x2e, (byte)0x6c, (byte)0x61, (byte)0x6e,
531                     (byte)0x67, (byte)0x2e, (byte)0x4f, (byte)0x62, (byte)0x6a, (byte)0x65, (byte)0x63, (byte)0x74,
532                     (byte)0x3b, (byte)0x90, (byte)0xce, (byte)0x58, (byte)0x9f, (byte)0x10, (byte)0x73, (byte)0x29,
533                     (byte)0x6c, (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x78, (byte)0x70, (byte)0x78,
534                 } },
535         };
536         for (Object[] c : cases) {
537             MethodType mt = (MethodType) c[0];
538             System.out.println("deserialize "+mt);
539             byte[] wire = (byte[]) c[1];
540             if (generateData) {
541                 System.out.println("<generateData>");
542                 wire = writeSerial(mt);
543                 final String INDENT = "                ";
544                 System.out.print("{  // "+mt);
545                 for (int i = 0; i < wire.length; i++) {
546                     if (i % 8 == 0) { System.out.println(); System.out.print(INDENT+"   "); }
547                     String hex = Integer.toHexString(wire[i] & 0xFF);
548                     if (hex.length() == 1)  hex = "0"+hex;
549                     System.out.print(" (byte)0x"+hex+",");
550                 }
551                 System.out.println();
552                 System.out.println(INDENT+"}");
553                 System.out.println("</generateData>");
554                 System.out.flush();
555             }
556             Object decode;
557             try {
558                 decode = readSerial(wire);
559             } catch (Exception ex) {
560                 decode = ex;  // oops!
561             }
562             assertEquals(mt, decode);
563         }
564     }
565 }